{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0 1 0 1 0 1 0 1]\n",
      " [1 0 1 0 1 0 1 0]\n",
      " [0 1 0 1 0 1 0 1]\n",
      " [1 0 1 0 1 0 1 0]\n",
      " [0 1 0 1 0 1 0 1]\n",
      " [1 0 1 0 1 0 1 0]\n",
      " [0 1 0 1 0 1 0 1]\n",
      " [1 0 1 0 1 0 1 0]]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "#1:8*8棋盘矩阵，其中1、3、5、7行&&0、2、4、6列的元素置为1   1 ,3，5，7列&&0,2,4,6行也是1\n",
    "z = np.zeros((8,8),dtype=int)\n",
    "z[1::2,::2] = 1\n",
    "z[::2,1::2] = 1\n",
    "print z\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#2：min()、max()函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "z = np.random.random((10,10))\n",
    "zmin,zmax = z.min(),z.max()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 5.64509768  0.68146094  8.23694681  0.07100285  7.37379186]\n",
      " [ 0.0752762   9.7764589   7.80421002  6.11552908  2.6865688 ]\n",
      " [ 9.8869914   1.44285425  0.89132992  2.59310328  0.56864919]\n",
      " [ 6.55186281  8.26647432  6.15930931  4.22051594  7.03349304]\n",
      " [ 4.74498093  0.58582793  3.09918065  2.54389279  7.28846041]]\n",
      "[[  5.67858734e-01   6.21901795e-02   8.31902351e-01   0.00000000e+00\n",
      "    7.43968778e-01]\n",
      " [  4.35345679e-04   9.88739545e-01   7.87817461e-01   6.15783749e-01\n",
      "    2.66459759e-01]\n",
      " [  1.00000000e+00   1.39756825e-01   8.35704993e-02   2.56937996e-01\n",
      "    5.06975256e-02]\n",
      " [  6.60235078e-01   8.34910455e-01   6.20243842e-01   4.22730025e-01\n",
      "    7.09300970e-01]\n",
      " [  4.76159692e-01   5.24476039e-02   3.08494430e-01   2.51924697e-01\n",
      "    7.35275670e-01]]\n"
     ]
    }
   ],
   "source": [
    "#归一化，将矩阵规格化到0～1，即最小的变成0，最大的变成1，最小与最大之间的等比缩放\n",
    "z = 10*np.random.random((5,5))\n",
    "print z\n",
    "zmin,zmax = z.min(),z.max()\n",
    "z = (z-zmin)/(zmax-zmin)\n",
    "print z"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0 1 2 3 4]\n",
      "[[ 0.  1.  2.  3.  4.]\n",
      " [ 0.  1.  2.  3.  4.]\n",
      " [ 0.  1.  2.  3.  4.]\n",
      " [ 0.  1.  2.  3.  4.]\n",
      " [ 0.  1.  2.  3.  4.]]\n"
     ]
    }
   ],
   "source": [
    "#矩阵相加\n",
    "z = np.zeros((5,5))\n",
    "z += np.arange(5)\n",
    "print np.arange(5)\n",
    "print z\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(array([  0.,   1.,   2.,   3.,   4.,   5.,   6.,   7.,   8.,   9.,  10.]), 1.0)\n"
     ]
    }
   ],
   "source": [
    "#生成0~10之间均匀分布的11个数，包括0和10\n",
    "\n",
    "z = np.linspace(0,10,11,endpoint=True,retstep=True)\n",
    "print z\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on function linspace in module numpy.core.function_base:\n",
      "\n",
      "linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)\n",
      "    Return evenly spaced numbers over a specified interval.\n",
      "    \n",
      "    Returns `num` evenly spaced samples, calculated over the\n",
      "    interval [`start`, `stop`].\n",
      "    \n",
      "    The endpoint of the interval can optionally be excluded.\n",
      "    \n",
      "    Parameters\n",
      "    ----------\n",
      "    start : scalar\n",
      "        The starting value of the sequence.\n",
      "    stop : scalar\n",
      "        The end value of the sequence, unless `endpoint` is set to False.\n",
      "        In that case, the sequence consists of all but the last of ``num + 1``\n",
      "        evenly spaced samples, so that `stop` is excluded.  Note that the step\n",
      "        size changes when `endpoint` is False.\n",
      "    num : int, optional\n",
      "        Number of samples to generate. Default is 50. Must be non-negative.\n",
      "    endpoint : bool, optional\n",
      "        If True, `stop` is the last sample. Otherwise, it is not included.\n",
      "        Default is True.\n",
      "    retstep : bool, optional\n",
      "        If True, return (`samples`, `step`), where `step` is the spacing\n",
      "        between samples.\n",
      "    dtype : dtype, optional\n",
      "        The type of the output array.  If `dtype` is not given, infer the data\n",
      "        type from the other input arguments.\n",
      "    \n",
      "        .. versionadded:: 1.9.0\n",
      "    \n",
      "    Returns\n",
      "    -------\n",
      "    samples : ndarray\n",
      "        There are `num` equally spaced samples in the closed interval\n",
      "        ``[start, stop]`` or the half-open interval ``[start, stop)``\n",
      "        (depending on whether `endpoint` is True or False).\n",
      "    step : float\n",
      "        Only returned if `retstep` is True\n",
      "    \n",
      "        Size of spacing between samples.\n",
      "    \n",
      "    \n",
      "    See Also\n",
      "    --------\n",
      "    arange : Similar to `linspace`, but uses a step size (instead of the\n",
      "             number of samples).\n",
      "    logspace : Samples uniformly distributed in log space.\n",
      "    \n",
      "    Examples\n",
      "    --------\n",
      "    >>> np.linspace(2.0, 3.0, num=5)\n",
      "        array([ 2.  ,  2.25,  2.5 ,  2.75,  3.  ])\n",
      "    >>> np.linspace(2.0, 3.0, num=5, endpoint=False)\n",
      "        array([ 2. ,  2.2,  2.4,  2.6,  2.8])\n",
      "    >>> np.linspace(2.0, 3.0, num=5, retstep=True)\n",
      "        (array([ 2.  ,  2.25,  2.5 ,  2.75,  3.  ]), 0.25)\n",
      "    \n",
      "    Graphical illustration:\n",
      "    \n",
      "    >>> import matplotlib.pyplot as plt\n",
      "    >>> N = 8\n",
      "    >>> y = np.zeros(N)\n",
      "    >>> x1 = np.linspace(0, 10, N, endpoint=True)\n",
      "    >>> x2 = np.linspace(0, 10, N, endpoint=False)\n",
      "    >>> plt.plot(x1, y, 'o')\n",
      "    [<matplotlib.lines.Line2D object at 0x...>]\n",
      "    >>> plt.plot(x2, y + 0.5, 'o')\n",
      "    [<matplotlib.lines.Line2D object at 0x...>]\n",
      "    >>> plt.ylim([-0.5, 1])\n",
      "    (-0.5, 1)\n",
      "    >>> plt.show()\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(np.linspace)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
